package Demo3;

import java.util.Objects;

public class Student implements Cloneable{
    private String name;
    private int age;

    private IDcard iDcard = new IDcard(123);

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    protected Student clone() throws CloneNotSupportedException {
        //先创建整体
        Student temp = (Student) super.clone();
        //创建局部
        IDcard clone = (IDcard) this.iDcard.clone();
        //局部赋值
        temp.iDcard = clone;
        return temp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public IDcard getiDcard() {
        return iDcard;
    }

    public void setiDcard(int number) {
        this.iDcard.number = number;
    }

    public Student(IDcard iDcard) {
        this.iDcard = iDcard;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name) && Objects.equals(iDcard, student.iDcard);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, iDcard);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", iDcard=" + iDcard.number +
                '}';
    }
}
